# SET(CUR_ARCH "aarch64")
# SET(CUR_ARCH "armhf")
SET(CUR_ARCH "x86_64")
SET(PREFIX /home/sunjie/work)
# SET(PREFIX /home/zyx/work)


SET(CMAKE_C_FLAGS "-O3 -fPIC -ldl -lpthread -fopenmp -lrt -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14 -fpermissive")


SET(EXTERNAL_LIB "-lrt -ldl -lpthread")
message("external flags" ${EXTERNAL_LIB})

SET(STREAM_DIR ${PROJECT_SOURCE_DIR})
SET(OSD_DIR ${PROJECT_SOURCE_DIR}/../osd)
SET(UTIL_DIR ${PROJECT_SOURCE_DIR}/../base_util)
aux_source_directory(${UTIL_DIR} util_src)


SET(CUDA_SOURCE
${util_src}

${STREAM_DIR}/base_puller.cpp
${STREAM_DIR}/osd_text.cpp
${STREAM_DIR}/cuda/stream_puller.cpp
${STREAM_DIR}/cuda/stream_pusher.cpp
${STREAM_DIR}/cuda/yuv_to_rgb.cpp
${STREAM_DIR}/cuda/main.cpp
)


SET(STREAM_NAME stream.cuda)
add_executable(${STREAM_NAME} ${CUDA_SOURCE})

# add_library(${TARGET_NAME} SHARED ${MODEL_SOURCE})
# set_target_properties(${TARGET_NAME} PROPERTIES VERSION 1.0.0 SOVERSION 1)

include_directories(${PROJECT_SOURCE_DIR})

include_directories(${PROJECT_SOURCE_DIR}/..)
include_directories(${SDK_DIR})

# ffmpeg
SET(FFMPEG_PATH ${PREFIX}/lib/ffmpeg_build.cuda.${CUR_ARCH})
set(FFMPEG_LIB
    ${FFMPEG_PATH}/lib/libavcodec.so.58
    ${FFMPEG_PATH}/lib/libavfilter.so.7
    ${FFMPEG_PATH}/lib/libavformat.so.58
    ${FFMPEG_PATH}/lib/libavutil.so.56
    ${FFMPEG_PATH}/lib/libswresample.so.3
    ${FFMPEG_PATH}/lib/libswscale.so.5
)
include_directories(${FFMPEG_PATH}/include)
target_link_libraries(${STREAM_NAME} ${FFMPEG_LIB})

# cuda
SET(CUDA_PATH /usr/local/cuda-11.8)
SET(ONNX_PATH ${PREFIX}/lib/onnxruntime-1.16.1/install.${CUR_ARCH})
set(CUDA_LIB
    ${CUDA_PATH}/lib64/libcudart.so
    ${ONNX_PATH}/lib/libyuvtorgb_kernel.so
)
include_directories(${CUDA_PATH}/include)
target_link_libraries(${STREAM_NAME} ${CUDA_LIB})

# openssl
SET(OPENSSL_PATH "${PREFIX}/lib/openssl-1.1.1q/install.${CUR_ARCH}")
set(OPENSSL_LIB
    ${OPENSSL_PATH}/lib/libcrypto.so.1.1
    ${OPENSSL_PATH}/lib/libssl.so.1.1
)
include_directories(${OPENSSL_PATH}/include)
target_link_libraries(${STREAM_NAME} ${OPENSSL_LIB})

# opencv
SET(OPENCV_PATH ${PREFIX}/lib/opencv-4.5.2/install.ffmpeg.cuda.${CUR_ARCH})
set(OPENCV_LIB ${OPENCV_PATH}/lib/libopencv_world.so.4.5)
include_directories(${OPENCV_PATH}/include/opencv4)
target_link_libraries(${STREAM_NAME} ${OPENCV_LIB})

# freetype
SET(FREE_PATH ${PREFIX}/lib/freetype-2.13.2/install.${CUR_ARCH})
set(FREE_LIB ${FREE_PATH}/lib/libfreetype.so.6.20.1)
include_directories(${FREE_PATH}/include/freetype2)
target_link_libraries(${STREAM_NAME} ${FREE_LIB})

#harfbuzz
SET(HARF_PATH ${PREFIX}/lib/harfbuzz-7.2.0/install.${CUR_ARCH})
set(HARF_LIB ${HARF_PATH}/lib/libharfbuzz.so.0.60720.0)
include_directories(${HARF_PATH}/include/harfbuzz)
target_link_libraries(${STREAM_NAME} ${HARF_LIB})

# boost
SET(BOOST_PATH "${PREFIX}/lib/boost_1_67_0")
set(BOOST_LIB
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_filesystem.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_system.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_date_time.a
    ${BOOST_PATH}/stage/lib.${CUR_ARCH}/libboost_regex.a
)
include_directories(${BOOST_PATH})
target_link_libraries(${STREAM_NAME} ${BOOST_LIB})


# json
SET(JSONCPP_PATH ${PREFIX}/lib/jsoncpp-1.9.5/install.${CUR_ARCH})
set(JSONCPP_LIB ${JSONCPP_PATH}/lib/libjsoncpp.a)
include_directories(${JSONCPP_PATH}/include)
target_link_libraries(${STREAM_NAME} ${JSONCPP_LIB})

# spdlog
SET(SPDLOG_PATH ${PREFIX}/lib/spdlog-1.9.2/install.${CUR_ARCH})
set(SPDLOG_LIB ${SPDLOG_PATH}/lib/libspdlog.a)
include_directories(${SPDLOG_PATH}/include)
target_link_libraries(${STREAM_NAME} ${SPDLOG_LIB})

# yaml
SET(YAML_PATH ${PREFIX}/lib/yaml-cpp-yaml-cpp-0.6.2/install.${CUR_ARCH})
set(YAML_LIB ${YAML_PATH}/lib/libyaml-cpp.a)
include_directories(${YAML_PATH}/include)
target_link_libraries(${STREAM_NAME} ${YAML_LIB})


target_link_libraries(${STREAM_NAME} ${CMAKE_CXX_FLAGS} ${EXTERNAL_LIB})

